from django.db import models
from Administrative_office_system.utils.BaseModel import BaseModel, IssueStampFileName
# Create your models here.
from personal_center.models import User
from administrative.models import VehicleApply



class SalaryRecord(BaseModel):
    user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    personnel_number = models.CharField(max_length=50, verbose_name='人员编号', default='')
    real_name = models.CharField(max_length=50, verbose_name='人员姓名', default='')
    personnel_category = models.CharField(max_length=32, verbose_name='人员类别', default='')
    company = models.CharField(max_length=50, verbose_name='科室', default='')
    bank_account = models.CharField(max_length=225, verbose_name='银行账号', default='')
    post_wage = models.CharField(max_length=30, verbose_name='岗位工资', default='')
    salary_level_salary = models.CharField(max_length=30, verbose_name='薪级工资', default='')
    standard_performance = models.CharField(max_length=30, verbose_name='标准绩效', default='')
    protective_tape = models.CharField(max_length=30, verbose_name='护贴', default='')
    car_tape = models.CharField(max_length=30, verbose_name='车贴', default='')
    health_allowance = models.CharField(max_length=30, verbose_name='卫生津贴', default='')
    labor_insurance = models.CharField(max_length=30, verbose_name='卫生劳保费', default='')
    total_payable = models.CharField(max_length=30, verbose_name='应发合计', default='')
    endowment_insurance = models.CharField(max_length=30, verbose_name='养老保险', default='')
    occupational_annuity = models.CharField(max_length=30, verbose_name='职业年金', default='')
    medical_insurance = models.CharField(max_length=30, verbose_name='医疗保险', default='')
    unemployment_insurance = models.CharField(max_length=30, verbose_name='失业保险', default='')
    housing_fund = models.CharField(max_length=30, verbose_name='公积金', default='')
    deduction_insurance = models.CharField(max_length=30, verbose_name='补扣保险', default='')
    deduction = models.CharField(max_length=30, verbose_name='扣款', default='')
    hydropower = models.CharField(max_length=30, verbose_name='水电费', default='')
    other = models.CharField(max_length=30, verbose_name='其它', default='')
    membership_fees = models.CharField(max_length=30, verbose_name='会费', default='')
    total_deduction = models.CharField(max_length=30, verbose_name='扣款合计', default='')
    predict_amount = models.CharField(max_length=30, verbose_name='工资实发', default='')
    month = models.CharField(max_length=10, verbose_name='月份', default='')
    years = models.CharField(max_length=10, verbose_name='年份', default='')
    types = models.CharField(max_length=10, verbose_name='类型：1、工资；2、绩效', default='')

class PerformanceRecord(BaseModel):
    user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    department_number = models.CharField(max_length=100, verbose_name='科室编号', default='')
    department = models.CharField(max_length=100, verbose_name='科室', default='')
    post = models.CharField(max_length=100, verbose_name='职务', default='')
    category = models.CharField(max_length=100, verbose_name='类别', default='')
    job_id = models.CharField(max_length=100, verbose_name='工号', default='')
    names = models.CharField(max_length=100, verbose_name='姓名', default='')
    bank_number = models.CharField(max_length=100, verbose_name='银行帐号', default='')
    workload_performance = models.CharField(max_length=100, verbose_name='工作量绩效', default='')
    management_performance = models.CharField(max_length=100, verbose_name='科主任管理绩效', default='')
    night_performance = models.CharField(max_length=100, verbose_name='夜班绩效', default='')
    consultation_performance = models.CharField(max_length=100, verbose_name='会诊绩效', default='')
    expert_performance = models.CharField(max_length=100, verbose_name='专家号绩效', default='')
    medical_performance = models.CharField(max_length=100, verbose_name='医共体绩效', default='')
    individual_performance = models.CharField(max_length=100, verbose_name='其他单项绩效', default='')
    parking_performance = models.CharField(max_length=100, verbose_name='停车绩效', default='')
    talent_performance = models.CharField(max_length=100, verbose_name='人才储备绩效', default='')
    public_performance = models.CharField(max_length=100, verbose_name='公卫绩效', default='')
    deduction = models.CharField(max_length=100, verbose_name='扣款', default='')
    payable_performance = models.CharField(max_length=100, verbose_name='应发绩效合计', default='')
    personal_income_tax = models.CharField(max_length=100, verbose_name='个人所得税', default='')
    actual_performance = models.CharField(max_length=100, verbose_name='实发绩效', default='')
    deduction_remarks = models.CharField(max_length=100, verbose_name='扣款备注', default='')
    month = models.CharField(max_length=10, verbose_name='月份', default='')
    years = models.CharField(max_length=10, verbose_name='年份', default='')


class TravelApply(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人'),
        ('two', '分管科室'),
        ('three', '报备科室'),
        ('four', '科室分管领导'),
        ('five', '结束'),
        ('eight', '拒绝'),
        ('stop', '终止')
    )
    TYPE = (
        ('one', '学术会议出差'),
        ('two', '进修出差'),
        ('three', '行政出差'),
        ('four', '其他')
    )
    USER_TYPE = (
        ('one', '临床医技人员'),
        ('two', '护理人员')
    )
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    ReportingDepartment = models.ManyToManyField('administrative.Company', verbose_name="报备科室", related_name='ReportingDepartment', blank=True)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='travel_apply_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='travel_apply_already_audit_users', blank=True)
    travel_users = models.ManyToManyField('personal_center.User', verbose_name='出行人员', related_name='travel_apply_users', blank=True)
    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    travel_type = models.CharField('差旅类型', max_length=10, choices=TYPE, default='three')
    user_type = models.CharField('人员类型', max_length=10, choices=USER_TYPE, default='one')
    start_time = models.CharField(max_length=50, verbose_name='出差开始时间', default='')
    end_time = models.CharField(max_length=50, verbose_name='出差结束时间', default='')
    note = models.TextField(verbose_name="备注", default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    subject = models.TextField(max_length=100, verbose_name='事由', default='')
    route = models.CharField(max_length=50, verbose_name='地点', default='')
    is_leader = models.BooleanField(default=False, verbose_name="是否有科室领导")
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    relevance = models.CharField('是否被关联', max_length=50, default='0')
    def get_state_str(self):
        if self.state == "five":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return "终止"
        elif self.state == 'recall':
            return "撤回"
        elif self.state == 'draft':
            return "草稿"
        else:
            return '审核中'


class TravelApplyAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人'),
        ('two', '分管科室'),
        ('three', '报备科室'),
        ('four', '科室分管领导')
    )

    parent_id = models.ForeignKey(
        'TravelApply',
        verbose_name="出差申请",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='CD')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见")


class MedicalMaterials(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '设备科长审核'),
        ('two', '材料会计核对'),
        ('three', '财务科长审核'),
        ('four', '分管院长签字'),
        ('five', '院长/书记签字'),
        ('six', '财务科支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )

    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='medical_materials_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='medical_materials_already_audit_users', blank=True)
    accounting = models.CharField(max_length=50, verbose_name='会计', default='')
    title = models.CharField(max_length=255, verbose_name='付款标题', default='')
    source = models.CharField(max_length=128, verbose_name='经费来源', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    total_amount = models.CharField(max_length=255, verbose_name='付款总金额', default='')
    daxie = models.CharField(max_length=255, verbose_name='总金额大写', default='')
    remake = models.TextField(verbose_name='备注', default='')
    detail_pay = models.TextField(verbose_name='付款明细', default='')
    payee = models.CharField('收款单位', max_length=255, default='')
    payee_account = models.CharField('收款账号', max_length=32, default='')
    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class MedicalMaterialsAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '设备科长'),
        ('two', '材料会计'),
        ('three', '财务科长'),
        ('four', '分管副院长'),
        ('five', '院长/书记'),
        ('six', '财务科支付'),
    )

    parent_id = models.ForeignKey(
        'MedicalMaterials',
        verbose_name="卫生材料付款审批",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class MaintainServer(BaseModel):
    STATE = (
        ('one', '设备科长审核'),
        ('two', '财务科长审核'),
        ('three', '设备科分管院长签字'),
        ('four', '书记/院长审批'),
        ('five', '财务科支付'),
        ('six', '结束'),
        ('seven', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
        ('draft', '草稿')
    )
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    title = models.CharField(max_length=100, verbose_name="付款标题")
    total_money = models.FloatField(verbose_name='付款总金额')
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="上传科室",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    financial = models.CharField(max_length=225, verbose_name="经费来源", default="")
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    state = models.CharField('状态', max_length=10, choices=STATE, default='one')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='maintain_server_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='maintain_server_already_audit_users', blank=True)

    def get_str_state(self):
        if self.state == 'six':
            return '结束'
        elif self.state == 'seven':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class MaintainServerAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('B', '分管领导'),
        ('SJ/YZ', '书记/院长'),
        ('SBKZ', '设备科长'),
        ('CWKZ', '财务科长'),
        ('CWK', '财务科')
    )
    parent_id = models.ForeignKey(
        'MaintainServer',
        verbose_name="维修维保服务付款",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='SBKZ')


class GeneralFinance(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '财务科长审核'),
        ('three', '科室分管领导审批'),
        ('four', '院领导审批'),
        ('five', '财务科支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )

    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        related_name="GeneralApplyUser",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='general_finance_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='general_finance_already_audit_users', blank=True)
    title = models.CharField(max_length=255, verbose_name='项目名称', default='')
    # source = models.CharField(max_length=128, verbose_name='经费来源', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    total_amount = models.CharField(max_length=255, verbose_name='付款总金额', default='')
    quantity = models.CharField(max_length=20, verbose_name='数量', default='')
    price = models.CharField(max_length=50, verbose_name='单价', default='')
    remake = models.CharField(max_length=255, verbose_name='备注', default='')
    daxie = models.CharField(max_length=255, verbose_name='总金额大写', default='')
    detail_pay = models.TextField(verbose_name='付款明细小节', default='')
    leader = models.ForeignKey('personal_center.User', verbose_name="分管领导", related_name="GeneralLeader", blank=True, null=True, on_delete=models.SET_NULL)
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    payee = models.CharField('收款单位', max_length=255, default='')
    payee_account = models.CharField('收款账号', max_length=255, default='')
    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class GeneralFinanceAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人'),
        ('two', '财务科长'),
        ('three', '科室分管领导'),
        ('four', '院领导'),
        ('five', '财务科支付'),
    )

    parent_id = models.ForeignKey(
        'GeneralFinance',
        verbose_name="普通项目付款审批",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class LogisticsOffice(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('zero', '会计审核'),
        ('one', '科室负责人审核'),
        ('two', '财务科长/审计科会计审批'),
        ('three', '财务科科长审批'),
        ('four', '分管领导'),
        ('five', '院领导审批'),
        ('six', '财务科支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    TYPE = (
        ('materials', '总务材料付款'),
        ('epiboly', '外包业务付款')
    )
    NOTE = (
        ('a', '自筹资金'),
        ('b', '专项资金')
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="员工", blank=True, null=True,
                                   on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="科室", blank=True, null=True,
                                on_delete=models.CASCADE)
    fund_type = models.CharField('款项类型', max_length=10, choices=TYPE, default='epiboly')
    total_money = models.CharField(max_length=100, verbose_name='付款总金额', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    payee = models.CharField(max_length=128, verbose_name='收款单位')
    payee_account = models.CharField(max_length=32, verbose_name='收款账户')
    note = models.CharField("经费来源", max_length=32,  choices=NOTE, default='a')
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    pay_reason = models.CharField(max_length=255, verbose_name='付款事由')
    daxie = models.CharField(max_length=255, verbose_name='大写')
    rask = models.CharField(max_length=500, verbose_name='备注')
    BankDeposit = models.CharField(max_length=225, verbose_name='开户行', default='')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='logistics_office_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='logistics_office_already_audit_users', blank=True)

    def get_str_state(self):
        if self.state == 'seven':
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'

    def get_fund_type(self):
        if self.fund_type == 'materials':
            return '总务材料付款'
        elif self.fund_type == 'epiboly':
            return '外包业务付款'

    def get_note_str(self):
        if self.note == "a":
            return '自筹资金'
        elif self.note == 'b':
            return '专项资金'


class LogisticsOfficeAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('zero', '会计审核'),
        ('one', '科室负责人审核'),
        ('two', '财务科长/审计科会计审批'),
        ('three', '财务科科长审批'),
        ('four', '分管领导'),
        ('five', '院领导审批'),
        ('six', '财务科支付')
    )
    parent_id = models.ForeignKey(
        'LogisticsOffice',
        verbose_name="总务科付款",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


# 请假流程
class LeaveRequest(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '主管部门审核(医务科或者护理部)'),
        ('three', '业务分管院长'),
        ('four', '人事科审核'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    TYPE = (
        ('a', '年休假'),
        ('b', '婚假'),
        ('c', '丧假'),
        ('d', '事假'),
        ('e', '病假'),
        ('f', '探亲假'),
        ('g', '放射假'),
        ('h', '产假'),
        ('i', '计生假'),
        ('j', '育儿假'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="员工", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="科室", blank=True, null=True, on_delete=models.CASCADE)
    leave_type = models.CharField('请假类型', max_length=10, choices=TYPE, default='d')
    job_num = models.CharField(verbose_name="工号", max_length=10, default='')
    reason = models.TextField(verbose_name='理由', default='')
    # start_time = models.DateTimeField('开始时间', auto_now_add=False)
    # end_time = models.DateTimeField('结束时间', auto_now_add=False)
    start_time = models.CharField(verbose_name='开始时间', max_length=50, null=True, default='')
    end_time = models.CharField(verbose_name='结束时间', max_length=50, null=True, default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    days = models.IntegerField(verbose_name='请假天数', default=0)
    group_grade = models.CharField(verbose_name='人员等级', max_length=10, default='')
    can_revise = models.CharField('是否可以修改', max_length=10, default='1')
    people_type = models.CharField('人员类别', max_length=10, default='1')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='leave_request_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='leave_request_already_audit_users', blank=True)

    def get_str_state(self):
        if self.state == 'seven':
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'

    def get_leave_type(self):
        if self.leave_type == 'a':
            return '年休假'
        elif self.leave_type == 'b':
            return '婚假'
        elif self.leave_type == 'c':
            return '丧假'
        elif self.leave_type == 'd':
            return '事假'
        elif self.leave_type == 'e':
            return '病假'
        elif self.leave_type == 'f':
            return '探亲假'
        elif self.leave_type == 'g':
            return '放射假'
        elif self.leave_type == 'h':
            return '产假'
        elif self.leave_type == 'i':
            return '计生假'
        else:
            return '育儿假'


class LeaveRequestAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '主管部门审核(医务科或者护理部)'),
        ('three', '业务分管院长'),
        ('four', '人事科审核'),
    )
    parent_id = models.ForeignKey(
        'LeaveRequest',
        verbose_name="请假审批",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class LeaveRequestTypeDays(BaseModel):
    TYPE = (
        ('a', '年休假'),
        ('b', '婚假'),
        ('c', '丧假'),
        ('d', '事假'),
        ('e', '病假'),
        ('f', '探亲假'),
        ('g', '放射假'),
        ('h', '产假'),
        ('i', '计生假'),
        ('j', '育儿假'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="请假人", blank=True, null=True, on_delete=models.SET_NULL)
    leave_type = models.CharField('请假类型', max_length=10, choices=TYPE, default='d')
    days = models.CharField('请假天数', max_length=128, blank=True, default='', null=True)
    years = models.CharField('请假年份', max_length=128, blank=True, default='', null=True)


class NutritionalMeals(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '分管领导或人事科审批'),
        ('three', '财务科长审批'),
        ('four', '营养科分管领导审批'),
        ('five', '院领导审批'),
        ('six', '财务支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    TYPE = (
        ('one', '误餐餐补'),
        ('two', '职工餐补'),
    )

    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='nutritional_meals_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='nutritional_meals_already_audit_users', blank=True)
    title = models.CharField(max_length=255, verbose_name='项目名称', default='')
    source = models.CharField(max_length=128, verbose_name='经费来源', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    total_amount = models.CharField(max_length=128, verbose_name='付款总金额', default='')
    type = models.CharField('用餐类型', max_length=10, choices=TYPE, default='draft')
    payee = models.CharField('收款单位', max_length=128, blank=True)
    account = models.CharField('收款账号', max_length=128, blank=True)
    detail_pay = models.TextField('付款明细', default='')
    daxie = models.CharField(max_length=255, verbose_name='付款金额大写', default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    DemandDepartment = models.CharField(max_length=255, verbose_name='需求科室', default='')
    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class NutritionalMealsAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人'),
        ('two', '分管领导或人事科审批'),
        ('three', '财务科审批'),
        ('four', '营养科分管领导审批'),
        ('five', '院领导审批'),
        ('six', '财务科支付'),
    )

    parent_id = models.ForeignKey(
        'NutritionalMeals',
        verbose_name="营养餐费付款审批",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class AuditEconomicContract(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '分管领导或人事科审批'),
        ('three', '财务科长审批'),
        ('four', '营养科分管领导审批'),
        ('five', '院领导审批'),
        ('six', '财务支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )

    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='audit_economic_contract_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='audit_economic_contract_already_audit_users', blank=True)
    contract_name = models.CharField(max_length=255, verbose_name='合同名称', default='')
    contract_number = models.CharField(max_length=255, verbose_name='合同编号', default='')
    filing = models.CharField(max_length=255, verbose_name='归档号', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    contract_amount = models.FloatField(verbose_name='合同金额', default=0)
    payee = models.CharField('对方单位', max_length=128, blank=True)
    source = models.CharField(max_length=128, verbose_name='经费来源', default='')
    content = models.TextField(verbose_name="合同内容主要条款", default='')

    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class NewMedicalServices(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '医务科/护理部负责人审批'),
        ('three', '审计科负责人审批'),
        ('four', '申请科室分管领导审批'),
        ('five', '审计科分管领导审批'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    TYPE = (
        ('one', '综合医疗服务类'),
        ('two', '医技诊疗类'),
        ('three', '临床诊疗类'),
    )
    CATEGORY = (
        ('a', '一般医疗服务'),
        ('b', '一般检查治疗'),
        ('c', '预防保健及其他'),
        ('d', '其他医疗服务项目'),
        ('e', '医学影像'),
        ('f', '超声检查'),
        ('g', '核医学'),
        ('h', '放射治疗'),
        ('i', '检验'),
        ('j', '血型与配血'),
        ('k', '病理检查'),
        ('m', '临床各种系统诊疗'),
        ('l', '经血管介入治疗'),
        ('n', '手术治疗'),
        ('o', '物理治疗与康复'),
        ('p', '中医及民族医诊疗类'),
    )

    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='add_new_medical_services_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='add_new_medical_services_already_audit_users', blank=True)
    title = models.CharField(max_length=255, verbose_name='项目名称', default='')
    number = models.CharField(max_length=255, verbose_name='项目编号', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    type = models.CharField('项目', max_length=10, choices=TYPE, default='one')
    category = models.CharField('项目类别', max_length=10, choices=CATEGORY, default='a')
    reason = models.TextField(verbose_name="申请理由", default='')
    connotation = models.TextField(verbose_name="项目内涵", default='')
    note = models.TextField(verbose_name="其他需要说明的情况", default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='0')
    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class NewMedicalServicesAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '医务科负责人审核'),
        ('two', '护理部负责人审批'),
        ('three', '审计科负责人审批'),
        ('four', '申请科室分管领导审批'),
        ('five', '审计科分管领导审批'),
    )

    parent_id = models.ForeignKey(
        'NewMedicalServices',
        verbose_name="科室新增医疗服务项目审批流程",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class SurgicalGrading(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '医务科负责人审批'),
        ('three', '医疗技术临床应用管理委员会审核'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )

    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='surgical_grading_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='surgical_grading_already_audit_users', blank=True)
    education = models.CharField(max_length=32, verbose_name='学历', default='')
    gender = models.CharField(max_length=10, choices=(('male', '男'), ('female', '女')), default='male', verbose_name='性别')
    birthday_date = models.CharField(max_length=50, verbose_name='出生日期')
    professional_title = models.CharField(max_length=32, verbose_name='职称', default='')
    professional_date = models.CharField(max_length=50, verbose_name='取得现有职称时间')
    note = models.TextField(verbose_name="备注", default='')
    fixed_business = models.CharField(max_length=32, verbose_name='定专业与否', default='')
    current_surgical_level = models.CharField(max_length=32, verbose_name='目前手术级别', default='')
    apply_surgical_level = models.CharField(max_length=32, verbose_name='申请手术级别', default='')
    reason = models.TextField(verbose_name="申请理由", default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    can_revise = models.CharField('是否可以修改', max_length=50, default='0')
    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class SurgicalGradingAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '医务科负责人审批'),
        ('three', '医疗技术临床应用管理委员会审核')
    )

    parent_id = models.ForeignKey(
        'SurgicalGrading',
        verbose_name="手术分级授权审批流程",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


# 离职申请
class Dimission(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('zero', '人事科初审'),
        ('one', '科室负责人审核'),
        ('two', '业务主管部门意见'),
        ('three', '业务分管院长意见'),
        ("four", '分管人事院长'),
        ('five', '调离通知确认'),
        ('six', '经管办'),
        ('seven', '财务科'),
        ('end', '结束'),
        ('refuse', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    user = models.ForeignKey('personal_center.User', verbose_name="员工", blank=True, null=True, on_delete=models.SET_NULL, related_name="DimissionApplyUser")
    company = models.ForeignKey('administrative.Company', verbose_name="科室", blank=True, null=True, on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='dimission_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='dimission_already_audit_users', blank=True)
    education = models.CharField(max_length=32, verbose_name='学历', default='')
    rank = models.CharField(max_length=32, verbose_name='职称', default='')
    dimission_note = models.TextField(verbose_name="离职原因", default='')
    hiredate = models.DateField(verbose_name='入职日期')
    dimission_time = models.DateField(verbose_name='拟离职日期')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    job_number = models.CharField(verbose_name='工号', max_length=10, blank=True)
    tel_num = models.CharField(verbose_name='联系方式', max_length=16, blank=True)
    group_grade = models.CharField(verbose_name='申请人权限等级', max_length=10, default='')
    people_type = models.CharField(verbose_name='人员类别', max_length=10, blank=True, default='')  # 1：行管，2：医技，3：护理
    before_status = models.CharField(verbose_name='退回之前流程状态', max_length=30, default='')
    returned_person = models.ForeignKey('personal_center.User', verbose_name="员工", blank=True, null=True, on_delete=models.SET_NULL, related_name="DimissionReturnedPerson")

    def get_state_str(self):
        if self.state == "end":
            return '结束'
        elif self.state == 'refuse':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class DimissionAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('zero', '人事科初审'),
        ('one', '科室负责人审核'),
        ('two', '业务主管部门意见'),
        ('three', '业务分管院长意见'),
        ("four", '分管人事院长'),
        ('five', '调离通知确认'),
        ('six', '经管办'),
        ('seven', '财务科'),
    )

    parent_id = models.ForeignKey(
        'Dimission',
        verbose_name="离职申请",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')
    node_name = models.CharField('节点名称', max_length=100, default='')



# 差旅报销
class TravelReimbursement(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('nine', '经费来源审核人'),
        ('two', '财务出纳审核报销单'),
        ('three', '分管领导'),
        ('four', '财务科长'),
        ('five', '院领导审核'),      # 小于 1W 戴立勇；大于1W小于20W 院长；大于20W 书记
        ('six', '出纳支付，上传支付凭证'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    AuditDepartment = models.CharField('审核科室', max_length=225, default='', null=True)
    business_matter = models.CharField('出差事由', max_length=225, default='')
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    apply_time = models.CharField('申请时间', max_length=225, default='')
    vote_reluse = models.CharField('是否派车', max_length=15, default='')
    business_days = models.CharField('出差天数', max_length=15, default='')
    hotel_expense = models.CharField('伙食费', max_length=15, default='')
    traffic_expense = models.CharField('市内交通费', max_length=15, default='')
    reimburse_dict = models.TextField(verbose_name='报销内容', default='')
    remarks = models.TextField(verbose_name='备注', default='')
    total = models.CharField('合计', max_length=100, default='')
    total_daxie = models.CharField('大写', max_length=255, default='')
    uuid = models.CharField('附件ID', max_length=50, default='')
    SourceFunds = models.CharField('经费类型', max_length=50, default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    payee = models.CharField('收款人', max_length=50, default='')
    relevance_list = models.CharField('用车流程ID列表', max_length=50, default=[])
    applicat = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    relevance = models.ForeignKey(
        'TravelApply',
        verbose_name="关联流程",
        blank=False,
        null=True,
        on_delete=models.CASCADE)
    relevance_car = models.ForeignKey(
        'administrative.VehicleApply',
        verbose_name="关联流程",
        blank=False,
        null=True,
        on_delete=models.CASCADE)
    relevance_zc = models.ForeignKey(
        'OutgoingCadresData',
        verbose_name="关联流程",
        blank=False,
        null=True,
        on_delete=models.CASCADE)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='travel_reimbursement_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='travel_reimbursement_already_audit_users', blank=True)
    travel_people = models.ManyToManyField('personal_center.User', verbose_name='出差人员', related_name='travel_reimbursement_people', blank=True)

    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        elif self.state == 'six':
            return '待付款'
        else:
            return '审核中'

class TravelReimbursementInvoiceNumber(BaseModel):
    parent_id = models.ForeignKey('TravelReimbursement', verbose_name="差旅报销", blank=False, null=False, on_delete=models.CASCADE)
    invoice_number = models.CharField('发票号', max_length=255, default="")

class TravelReimbursementAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人'),
        ('nine', '经费来源'),
        ('two', '财务出纳'),
        ('three', '审计科审核'),
        ('four', '财务科长'),
        ('five', '院领导审核'),  # 小于 1W 戴立勇；大于1W小于20W 院长；大于20W 书记
        ('six', '出纳支付')
    )

    parent_id = models.ForeignKey(
        'TravelReimbursement',
        verbose_name="差旅报销",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')

# 差旅付款凭证
class TravelReimbursementPayment(BaseModel):
    parent_id = models.ForeignKey(
        'TravelReimbursement',
        verbose_name="差旅报销",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    imgs = models.TextField(verbose_name="图片", default='')


class SoloPracticeApply(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '医务科负责人审批'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )

    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='solo_practice_apply_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='solo_practice_apply_already_audit_users', blank=True)
    birthday_date = models.CharField(max_length=128, verbose_name='出生日期', default='')
    university = models.CharField(max_length=32, verbose_name='毕业院校', default='')
    subject = models.CharField(max_length=32, verbose_name='所学专业', default='')
    doctor_qualified_number = models.CharField(max_length=128, verbose_name='医师资格证书编号', default='')
    doctor_qualified_date = models.CharField(max_length=128, verbose_name='医师资格证书取得时间', default='')
    doctor_ractice_number = models.CharField(max_length=128, verbose_name='医师执业证书编号', default='')
    doctor_ractice_date = models.CharField(max_length=128, verbose_name='医师执业证书取得时间', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    signature_picture = models.CharField('签名', max_length=128, blank=True)
    can_revise = models.CharField('是否可以修改', max_length=50, default='0')
    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class SoloPracticeApplyAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '医务科负责人审批'),
    )

    parent_id = models.ForeignKey(
        'SoloPracticeApply',
        verbose_name="临床医师单独执业资格申请",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class BusinessContract(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '申请科室负责人审核'),
        ('two', '物资需求科室负责人审批'),
        ('three', '财务科负责人审批'),
        ('four', '监察室负责人审批'),
        ('five', '审计科负责人审批'),
        ('six', '申请人分管领导'),
        ('nine', '书记院长审核'),
        ('ten', '法人审核'),
        ('eleven', '党政办审核盖章'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )

    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    product_company = models.ForeignKey(
        'administrative.Company',
        verbose_name="物资需求科室",
        related_name='business_contract_company',
        blank=True,
        null=True,
        on_delete=models.CASCADE, default='null')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='business_contract_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='business_contract_already_audit_users', blank=True)
    contract_name = models.CharField('合同名称', max_length=64, blank=True)
    contract_number = models.CharField('合同编号', max_length=64, blank=True)
    documentation = models.CharField('归档号', max_length=64, blank=True)
    other_units = models.CharField('对方单位', max_length=64, blank=True)
    contract_amount = models.CharField(max_length=100, verbose_name='合同金额', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    source = models.CharField(max_length=32, verbose_name='经费来源', default='')
    referral = models.CharField(max_length=10, verbose_name='是否转审', default=False)
    content = models.TextField(verbose_name="合同内容主要条款")
    contract_type = models.CharField(max_length=10, verbose_name='合同类型', default="1")               # 合同类型: 1、服务类；2、货物类
    contract_effect = models.CharField(max_length=32, verbose_name='合同生效日', default='')
    contract_off = models.CharField(max_length=32, verbose_name='合同截至日', default='')
    Printing = models.CharField(max_length=30, verbose_name='用印份数', default='')
    greater = models.CharField(max_length=30, verbose_name='金额是否大于20万', default='1')
    summary_path = models.CharField('纪要路径', max_length=225, blank=True, default='')
    summary_name = models.CharField('纪要名称', max_length=225, blank=True, default='')
    notes = models.CharField('备注', max_length=225, blank=True, default='')
    requirement_department = models.ManyToManyField('administrative.Company', verbose_name='物资需求科室', related_name='business_contract_requirement_department', blank=True)
    association_topic = models.ForeignKey('administrative.Topics', verbose_name="合同会签关联议题", related_name='business_association_topic', blank=True, null=True, on_delete=models.CASCADE, default='')
    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class BusinessContractAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '物资需求科室负责人审批'),
        ('three', '财务科负责人审批'),
        ('four', '监察室负责人审批'),
        ('five', '审计科负责人审批'),
        ('six', '申请人分管领导'),
        ('nine', '书记院长审核'),
        ('ten', '法人审核'),
        ('eleven', '党政办审核盖章')
    )

    parent_id = models.ForeignKey(
        'BusinessContract',
        verbose_name="审计科经济合同会签流程",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


# 临床用血费用付款流程
class PayWithBlood(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '材料会计审核'),
        ('two', '财务科科长审核'),
        ('three', '分管领导审核'),
        ('four', '财务科分管领导审核'),
        ('five', '书记/院长审核'),
        ('six', '财务科支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    title = models.CharField('标题', max_length=225, default='')
    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    total_amount = models.FloatField('付款金额', default=0)
    fj_number = models.CharField('附件编号', max_length=50, default='')
    remarks = models.TextField(verbose_name='备注', default='')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='pay_with_blood_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='pay_with_blood_already_audit_users', blank=True)

    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class PayWithBloodAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '材料会计审核'),
        ('two', '财务科科长审核'),
        ('three', '分管领导审核'),
        ('four', '财务科分管领导审核'),
        ('five', '书记/院长审核'),
        ('six', '财务科支付')
    )

    parent_id = models.ForeignKey(
        'PayWithBlood',
        verbose_name="临床用血费用付款流程",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')

# 中层干部外出
class OutgoingCadresData(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '分管部门'),
        ('two', '分管领导'),
        ('three', '党政办接收'),
        ('four', '党政办审核'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="员工",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    company = models.ForeignKey(
        'administrative.Company',
        verbose_name="科室",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    department_charge = models.ForeignKey(
        'administrative.Company',
        verbose_name='分管部门',
        related_name='department_charge',
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    outgoing_person = models.ManyToManyField('personal_center.User', verbose_name='外出人员', related_name='outgoing_person_data', blank=True)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='outgoing_cadres_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='outgoing_cadres_already_audit_users', blank=True)
    title = models.CharField('外出事由', max_length=1000, default='')
    start_time = models.CharField('外出开始时间', max_length=100, default='')
    end_time = models.CharField('外出结束时间', max_length=100, default='')
    duties = models.CharField('职务', max_length=225, default='')
    destination = models.CharField('目的地', max_length=225, default='')
    uuid = models.CharField('附件编号', max_length=50, default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    relevance = models.CharField('是否被关联', max_length=50, default='0')
    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'

class OutgoingCadresDataRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '分管部门'),
        ('two', '分管领导'),
        ('three', '党政办接收'),
        ('four', '党政办审核'),
    )

    parent_id = models.ForeignKey(
        'OutgoingCadresData',
        verbose_name="中层干部外出审批流程",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class LaborUnionExpenses(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '会计审核'),
        ('three', '审计科会计审批'),
        ('four', '财务科科长审批'),
        ('five', '分管领导'),
        ('six', '院领导审批'),
        ('nine', '财务科支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    total_money = models.CharField(max_length=100, verbose_name='付款总金额', default='')
    pay_type = models.CharField(max_length=20, verbose_name='付款类型', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    payee = models.CharField(max_length=128, verbose_name='收款单位')
    payee_account = models.CharField(max_length=32, verbose_name='收款账户')
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    pay_reason = models.CharField(max_length=255, verbose_name='付款事由')
    daxie = models.CharField(max_length=255, verbose_name='大写')
    rask = models.CharField(max_length=500, verbose_name='备注')
    BankDeposit = models.CharField(max_length=225, verbose_name='开户行', default='')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='laborUnion_expenses_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='laborUnion_expenses_already_audit_users', blank=True)
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')

    def get_str_state(self):
        if self.state == 'seven':
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class LaborUnionExpensesRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '会计审核'),
        ('three', '审计科会计审批'),
        ('four', '财务科科长审批'),
        ('five', '分管领导'),
        ('six', '院领导审批'),
        ('nine', '财务科支付')
    )
    parent_id = models.ForeignKey(
        'LaborUnionExpenses',
        verbose_name="工会经费",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')

class SubjectFunding(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '部门负责人'),
        ('three', '科教科分管领导'),
        ('four', '财务科科长审批'),
        ('five', '院领导审批'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    total_money = models.CharField(max_length=100, verbose_name='付款总金额', default='')
    pay_type = models.CharField(max_length=20, verbose_name='付款类型', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    pay_reason = models.CharField(max_length=255, verbose_name='申请事由')
    pay_detail = models.TextField(verbose_name='申请明细', default='', null=True)
    daxie = models.CharField(max_length=255, verbose_name='大写')
    rask = models.CharField(max_length=500, verbose_name='备注')
    people_type = models.CharField(max_length=11, verbose_name='人员类型', default="1")                  # 1：临床医技人员，2：行管人员
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='subject_funding_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='subject_funding_already_audit_users', blank=True)
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    payee = models.CharField(max_length=255, verbose_name='收款人', default='')
    account_number = models.CharField(max_length=255, verbose_name='收款账号', default='')

    def get_str_state(self):
        if self.state == 'seven':
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'

class SubjectFundingRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '部门负责人(科教科)'),
        ('three', '科教科分管领导'),
        ('four', '财务科科长审批'),
        ('five', '院领导审批')
    )
    parent_id = models.ForeignKey(
        'SubjectFunding',
        verbose_name="学科经费",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class SealMaking(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '党政办公室意见'),
        ('two', '分管院长意见'),
        ('three', '党政办公室接收'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('stop', '终止'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    making_number = models.IntegerField(verbose_name="刻印次数", default=1)
    plan_seal_name = models.CharField(max_length=32, verbose_name='拟刻印名称')
    reason = models.TextField(verbose_name='申请刻制理由', default='')
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    fj_number = models.CharField('附件id', max_length=225, default='')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='seal_making_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='seal_making_already_audit_users', blank=True)

    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'draft':
            return '草稿'
        elif self.state == "eight":
            return "拒绝"
        else:
            return '审核中'


class SealMakingRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '党政办公室意见'),
        ('two', '分管院长意见'),
        ('three', '党政办公室接收'),
    )
    parent_id = models.ForeignKey(
        'SealMaking',
        verbose_name="印章刻制申请",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


# 用户端——印章快捷授权主表
class QuickAuthorization(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '审计科审核'),
        ('two', '院长授权'),
        ('three', '分管领导接收'),
        ('four', '科主任接收'),
        ('five', '科员接收'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('stop', '终止'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL, related_name='apply_people')
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    quick = models.ForeignKey('QuickAuthorizationSeal', verbose_name="快捷授权", blank=True, null=True, on_delete=models.CASCADE)
    seal_name = models.ManyToManyField('personal_center.seal', verbose_name='授权印章名称', related_name='seal_making_audit_users', blank=True)
    reason = models.TextField(verbose_name='快捷用印类目', default='', null=True)
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    authorization_type = models.CharField('授权类型', max_length=32, default='')
    HandledBy = models.ForeignKey('personal_center.User', verbose_name="经办人", blank=True, null=True, on_delete=models.SET_NULL, related_name='Handled_By')
    remarks = models.TextField(verbose_name='备注', default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    can_related = models.CharField('是否可以关联', max_length=50, default='1')
    take_effect_time = models.CharField('生效时间', max_length=50, default='')
    lose_efficacy_time = models.CharField('失效时间', max_length=50, default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='quick_authorization_current', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='quick_authorization_already_audit_users', blank=True)


    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'draft':
            return '草稿'
        elif self.state == "eight":
            return "拒绝"
        else:
            return '审核中'

# 用户端——印章快捷授权审批表
class QuickAuthorizationRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '院长授权'),
        ('two', '分管领导指派授权人'),
        ('three', '科主任指派授权人'),
        ('four', '科员接收')
    )
    parent_id = models.ForeignKey(
        'QuickAuthorization',
        verbose_name="印章快捷授权",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')

# 管理端——快捷授权详情表
class QuickAuthorizationApplicationCategory(BaseModel):
    seal_id = models.ForeignKey('personal_center.seal', verbose_name="被授权印章", blank=True, null=True, on_delete=models.SET_NULL)
    authorized_person = models.ForeignKey('personal_center.User', verbose_name="被授权人", blank=True, null=True, on_delete=models.SET_NULL)
    category = models.CharField('授权类目', max_length=225, default='')
    authorization_type = models.CharField('是否授权', max_length=32, default='0')
    quick = models.ForeignKey('QuickAuthorizationSeal', verbose_name="快捷授权", blank=True, null=True, on_delete=models.CASCADE)
    level = models.CharField('授权级别', max_length=32, default='')         # 1：一级授权，2：二级授权，3：三级授权

# 管理端——快捷授权主表
class QuickAuthorizationSeal(BaseModel):
    detail_json = models.TextField(verbose_name='快捷用印详情', null=True)
    company = models.ForeignKey('administrative.Company', verbose_name="授权科室", blank=True, null=True, on_delete=models.CASCADE, default='')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=False, null=False, on_delete=models.CASCADE, default='', related_name='QuickApply')
    authorization_type = models.CharField('授权类型', max_length=11, default='')            # 1：法人授权，2：分管授权
    can_related = models.CharField('是否可以申请', max_length=50, default='1')
    take_effect_time = models.CharField('生效时间', max_length=50, default='')
    lose_efficacy_time = models.CharField('失效时间', max_length=50, default='')
    select_leader = models.ForeignKey('personal_center.User', verbose_name="分管领导", blank=True, null=True, on_delete=models.SET_NULL)

# 图书/报刊/杂志征订
class BookSubscription(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科主任审核'),
        ('two', '图书室查询'),
        ('three', '病案统计科'),
        ('four', '病案统计科分管领导'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('stop', '终止'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    reason = models.TextField(verbose_name='报刊杂志征订', default='', null=True)
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    book_buy = models.TextField(verbose_name='书记购买详情', default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    fj_number = models.CharField('附件id', max_length=50, default='')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='book_subscription_current', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='book_subscription_already_audit_users', blank=True)

    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'draft':
            return '草稿'
        elif self.state == "eight":
            return "拒绝"
        else:
            return '审核中'

class BookSubscriptionRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科主任审核'),
        ('two', '图书室查询'),
        ('three', '病案统计科'),
        ('four', '病案统计科分管领导')
    )
    parent_id = models.ForeignKey(
        'BookSubscription',
        verbose_name="图书/报刊/杂志征订",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')

# 考勤表信息
class CheckWorkTable(BaseModel):
    apply_user = models.ForeignKey('personal_center.User', verbose_name="提交人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="提交科室", blank=True, null=True, on_delete=models.CASCADE)
    gauge_outfit = models.CharField('表头', max_length=50, default='', null=True)
    state = models.CharField('节点', max_length=50, default='one', null=True)
    work_month = models.CharField('月份', max_length=50, default='', null=True)
    work_yesr = models.CharField('年份', max_length=50, default='', null=True)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='check_work_current', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='check_work_already_audit_users', blank=True)
    whether_verify = models.CharField('是否核对', max_length=11, default='0', null=True)
    WorkType = models.CharField('考勤类型', max_length=11, default='1', null=True)          # 1：员工考勤，2：劳务派遣考勤

class CheckWorkAttendance(BaseModel):
    attendance = models.ForeignKey('CheckWorkTable', verbose_name="考勤表", blank=True, null=True, on_delete=models.CASCADE)
    serial = models.IntegerField('序号', default=0, null=True)
    department = models.CharField('科室', max_length=50, default='', null=True)
    job_number = models.CharField('工号', max_length=20, default='', null=True)
    practice = models.CharField('执业', max_length=225, default='', null=True)
    name = models.CharField('姓名', max_length=20, default='', null=True)
    attendance_days = models.CharField('出勤天数', max_length=20, default='', null=True)
    work_days = models.CharField('上班', max_length=20, default='', null=True)
    aid_jing = models.CharField('援荆', max_length=20, default='', null=True)
    quarantine = models.CharField('隔离', max_length=20, default='', null=True)
    heterodyne = models.CharField('外差', max_length=20, default='', null=True)
    education = models.CharField('进修', max_length=20, default='', null=True)
    planning = models.CharField('计生假', max_length=20, default='', null=True)
    maternity = models.CharField('产假', max_length=20, default='', null=True)
    annual = models.CharField('年休', max_length=20, default='', null=True)
    absence = models.CharField('事假', max_length=20, default='', null=True)
    sick = models.CharField('病假', max_length=20, default='', null=True)
    industrial = models.CharField('工伤', max_length=20, default='', null=True)
    visit = models.CharField('探亲假', max_length=20, default='', null=True)
    marriage = models.CharField('婚假', max_length=20, default='', null=True)
    bereavement = models.CharField('丧假', max_length=20, default='', null=True)
    vacation = models.CharField('放射假', max_length=20, default='', null=True)
    parental_leave = models.CharField('育儿假', max_length=20, default='', null=True)
    notes = models.TextField('备注', default='', null=True)
    apply_user = models.ForeignKey('personal_center.User', verbose_name="人员", blank=True, null=True, on_delete=models.SET_NULL)

class CheckWorkLaborDispatch(BaseModel):
    attendance = models.ForeignKey('CheckWorkTable', verbose_name="考勤表", blank=True, null=True, on_delete=models.CASCADE)
    serial = models.IntegerField('序号', default=0, null=True)
    department = models.CharField('科室', max_length=50, default='', null=True)
    project_name = models.CharField('考核项目/姓名', max_length=255, default='', null=True)
    attendance_days = models.CharField('实际出勤天数', max_length=20, default='', null=True)
    leave_type = models.CharField('请假类别及天数', max_length=20, default='', null=True)
    labor_discipline = models.CharField('劳动纪律', max_length=20, default='', null=True)
    work_quality = models.CharField('工作质量', max_length=20, default='', null=True)
    working_ability = models.CharField('工作能力', max_length=20, default='', null=True)
    other = models.CharField('其他', max_length=20, default='', null=True)
    total_score = models.CharField('总得分', max_length=20, default='', null=True)
    notes = models.TextField('备注', default='', null=True)

class CheckWorkRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人签字'),
        ('two', '人事科负责人签字'),
    )
    parent_id = models.ForeignKey('CheckWorkTable', verbose_name="考勤表信息", blank=False, null=False, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')

# 党建经费
class PartyBuilding(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '支部书记审核'),
        ('two', '党政办审核'),
        ('three', '分管领导审核'),
        ('four', '财务科审核'),
        ('five', '院领导审核'),
        ('six', '财务科支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('stop', '终止'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", related_name="apply_user_people", blank=True, null=True, on_delete=models.SET_NULL)
    branch_review = models.ForeignKey('personal_center.User', verbose_name="支部审核人", related_name="branch_review_people", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='party_building_current', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='party_building_already_audit_users', blank=True)
    pay_detail = models.TextField(verbose_name='付款明细', default='')
    total_amount = models.CharField(max_length=255, verbose_name='付款总金额', default='')
    daxie = models.CharField(max_length=255, verbose_name='总金额大写', default='')
    fj_number = models.CharField('附件id', max_length=225, default='')
    dep_type = models.CharField(max_length=20, verbose_name='科室类型', default='')
    TypeId = models.CharField(max_length=20, verbose_name='申请部门(支部)', default='')
    payee = models.CharField(max_length=255, verbose_name='收款人', default='')
    account_number = models.CharField(max_length=255, verbose_name='收款账号', default='')
    application_reason = models.CharField(max_length=255, verbose_name='申请事由', default='')

    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'draft':
            return '草稿'
        elif self.state == "eight":
            return "拒绝"
        else:
            return '审核中'

class PartyBuildingRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '支部书记审核'),
        ('two', '党政办审核'),
        ('three', '分管领导审核'),
        ('four', '财务科审核'),
        ('five', '院领导审核'),
        ('six', '财务科支付')
    )
    parent_id = models.ForeignKey('PartyBuilding', verbose_name="党建经费", blank=False, null=False, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class ObjectAudit(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '分管领导审核'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('stop', '终止'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='object_audit_current', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='object_audit_already_audit_users', blank=True)
    w_time = models.CharField(max_length=64, verbose_name='填表时间', default='')
    r_time = models.CharField(max_length=64, verbose_name='收文时间', default='')
    work_name = models.CharField(max_length=512, verbose_name='项目名称', default='')
    describe = models.TextField(verbose_name="项目概述", default='')
    audit_ask = models.TextField(verbose_name="送审要求", default='')
    htje = models.CharField(verbose_name='合同金额', max_length=32, default='')
    sgfzj = models.CharField(verbose_name='施工方造价', max_length=32, default='')
    bmzj = models.CharField(verbose_name='本部门造价', max_length=32, default='')
    fj_number = models.CharField('附件id', max_length=516, default='')

    def get_state_str(self):
        if self.state == "seven":
            return '结束'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'draft':
            return '草稿'
        elif self.state == "eight":
            return "拒绝"
        else:
            return '审核中'


class ObjectAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '分管领导审核'),
    )
    parent_id = models.ForeignKey('ObjectAudit', verbose_name="项目送审", blank=False, null=False, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')


class ContractManagement(BaseModel):
    STATE = (
        ('1', '无需处理'),
        ('2', '未处理'),
        ('3', '已处理'),
    )
    TYPE = {
        ("1", "站内信提醒"),
        ("2", "短信提醒")
    }
    contract_name = models.CharField(max_length=255, verbose_name="合同名称", blank=False, default="", null=True)
    contract_effect = models.CharField(max_length=32, verbose_name='合同生效日', default='', null=True)
    contract_off = models.CharField(max_length=32, verbose_name='合同截至日', default='', null=True)
    remind_date = models.CharField(max_length=32, verbose_name='提醒日期', default='', null=True)
    handle = models.CharField('是否处理', max_length=32, choices=STATE, default='1')
    remind_type = models.CharField(max_length=32, verbose_name='提醒类型', default='', null=True)
    contract_path = models.CharField(max_length=255, verbose_name='合同路径', default='', null=True)
    describe = models.TextField(verbose_name="描述", default='', null=True)
    apply_user = models.ForeignKey('personal_center.User', verbose_name="上传人", blank=True, null=True, on_delete=models.SET_NULL)

class ResearchFunding(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '部门负责人'),
        ('three', '科教科分管领导'),
        ('four', '财务科科长审批'),
        ('five', '院领导审批'),
        ('six', '财务科支付'),
        ('seven', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    total_money = models.CharField(max_length=100, verbose_name='付款总金额', default='')
    pay_type = models.CharField(max_length=20, verbose_name='付款类型', default='')
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    pay_reason = models.CharField(max_length=255, verbose_name='申请事由')
    pay_detail = models.TextField(verbose_name='申请明细', default='', null=True)
    daxie = models.CharField(max_length=255, verbose_name='大写')
    rask = models.CharField(max_length=500, verbose_name='备注')
    people_type = models.CharField(max_length=11, verbose_name='人员类型', default="1")                  # 1：临床医技人员，2：行管人员
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='research_funding_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='research_funding_already_audit_users', blank=True)
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    payee = models.CharField(max_length=255, verbose_name='收款人', default='')
    account_number = models.CharField(max_length=255, verbose_name='收款账号', default='')

    def get_str_state(self):
        if self.state == 'seven':
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'

class ResearchFundingRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '部门负责人(科教科)'),
        ('three', '科教科分管领导'),
        ('four', '财务科科长审批'),
        ('five', '院领导审批'),
        ('six', '财务科支付'),
    )
    parent_id = models.ForeignKey(
        'ResearchFunding',
        verbose_name="科研经费",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')

class ConfidentialDataExport(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人审核'),
        ('two', '权限归属科室负责人'),
        ('three', '网络信息科负责人'),
        ('four', '监察室负责人'),
        ('five', '申请科室分管领导审批'),
        ('six', '网络信息科分管院长'),
        ('seven', '纪委书记'),
        ('end', '结束'),
        ('eight', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    TYPE = (
        ('one', '诊疗信息'),
        ('two', '财务数据'),
        ('three', '资产数据'),
        ('four', '人事信息'),
        ('five', '药品信息'),
        ('six', '其他信息'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, related_name="apply_company", on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='confidential_data_export_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='confidential_data_export_already_audit_users', blank=True)
    fj_number = models.CharField('附件编号', max_length=128, blank=True)
    state = models.CharField('状态', max_length=32, choices=STATE, default='one')
    information_type = models.CharField('信息类型', max_length=32, choices=TYPE, default='one')
    external_guidance_basis = models.CharField(max_length=255, verbose_name='外导依据', default="")
    application_reason = models.CharField(max_length=255, verbose_name='申请理由', default="")
    inspection_report = models.CharField(max_length=11, verbose_name='是否需要纪委报备', default="0")       # 是否需要纪委报备:1、是， 0：否
    meet_or_not = models.CharField(max_length=11, verbose_name='是否上会', default="0")  # 是否上会:1、是， 0：否
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')

    def get_state_str(self):
        if self.state == 'end':
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'

    def get_type_str(self):
        if self.information_type == 'one':
            return '诊疗信息'
        elif self.information_type == 'two':
            return '财务数据'
        elif self.information_type == 'three':
            return '资产数据'
        elif self.information_type == 'four':
            return '人事信息'
        elif self.information_type == 'five':
            return '药品信息'
        else:
            return '其他信息'

class ConfidentialDataExportRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人审核'),
        ('two', '网络信息科负责人'),
        ('three', '监察室负责人'),
        ('four', '申请科室分管领导审批'),
        ('five', '网络信息科分管院长'),
        ('six', '纪委书记')
    )
    parent_id = models.ForeignKey('ConfidentialDataExport', verbose_name="机密数据外导", blank=False, null=False, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", default='')